<script setup lang="ts">

import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { addOrder, DeleteOrder, getOrderList } from "@/api/property";
import { reactive, ref } from "vue";

const form = reactive({
  name: "",
  amount: 0,
  userId: 0,
  item: ""
});
const dataList = ref([]);
const onSearch = () => {
  getOrderList(form.name).then(res => {
    dataList.value = res.data;
  });
};
const AddOrder = () => {
  addOrder({
    item: form.item,
    userId: form.userId,
    amount: form.amount
  }).then(res => {
    onSearch();
  });
};
const deleteOrder = (id:number) => {
  DeleteOrder(id).then(res=>{
    onSearch();
  })
};
const flag = ref(false);
onSearch();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-form-item label="收费项目：" prop="name">
        <el-input
          v-model="form.name"
          placeholder="请输入收费项目"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon(Search)"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
        <el-button
          type="primary"
          @click="flag=true"
        >添加收费
        </el-button>
      </el-form-item>
      <br />
    </el-form>
    <el-table :data="dataList.records" table-layout="fixed">
      <el-table-column prop="id" label="ID" />
      <el-table-column label="收费金额">
        <template #default="scope">
          <el-tag type="warning">{{ scope.row.amount }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="created" label="收费时间" />
      <el-table-column prop="item" label="收费项目" />
      <el-table-column prop="outOrderId" label="支付订单号" />
      <el-table-column prop="userId" label="收费业主" />
      <el-table-column prop="status" label="收费状态">
        <template #default="scope">
          <el-tag v-if="scope.row.status===0" type="info">暂未创建订单</el-tag>
          <el-tag v-if="scope.row.status===1" type="danger">未支付</el-tag>
          <el-tag v-if="scope.row.status===2" type="success">已支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button
            type="danger"
            size="small"
            @click="deleteOrder(scope.row.id)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="width: 100%">
      <el-pagination
        style="float: right"
        background
        layout="prev, pager, next"
        :total="dataList.total"
        :page-count="dataList.current"
      />
    </div>
    <div>
      <!--      使用Dialog弹窗发布公告-->
      <el-dialog v-model="flag" title="新增收费" width="500" center>
        <el-form-item label="收费金额">
          <el-input v-model="form.amount" />
        </el-form-item>
        <el-form-item label="业主ID">
          <el-input v-model="form.userId" />
        </el-form-item>
        <el-form-item label="收费原因">
          <el-input v-model="form.item" />
        </el-form-item>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="flag = false">取消</el-button>
            <el-button type="primary"
                       @click="AddOrder();flag = false">
              确定
            </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<style scoped lang="scss">

</style>
